#include <iostream>
#include <queue>

using namespace std;

class Solution {
public:
    string reformat(string s) {
        queue<char> num;
        queue<char> zimu;
        string ans = "";
        ans.reserve(s.size());
        for (char& c : s) {
            if (c >= 'a' && c <= 'z') {
                zimu.push(c);
            } else {
                num.push(c);
            }
        }
        if (num.size() == zimu.size() + 1) {
            ans += num.front();
            num.pop();
            while (!num.empty() && !zimu.empty()) {
                ans += zimu.front();
                ans += num.front();
                zimu.pop();
                num.pop();
            }
        } else if (zimu.size() == num.size() + 1) {
            ans += zimu.front();
            zimu.pop();
            while (!num.empty() && !zimu.empty()) {
                ans += num.front();
                ans += zimu.front();
                zimu.pop();
                num.pop();
            }
        } else if (zimu.size() == num.size()) {
            while (!num.empty() && !zimu.empty()) {
                ans += num.front();
                ans += zimu.front();
                zimu.pop();
                num.pop();
            }
        }
        return ans;
    }
};